<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>vue中样式绑定</title>
</head>
<style>
    .activated {
        color: red;
    }
</style>
<body>
    <div id="app">
        <div @click="handleDivClick" 
            :class="{activated: isActivated}">
            {{ message }}
        </div>
        <div @click="handleDivClick" 
            :class="[activated, 'link']">
            {{ message }}
        </div>
        <div @click="handleDivClick" 
            :style="styleObj">
            {{ message }}
        </div>
    </div>
</body>
<script src="vue.js"></script>
<script>

    var vm = new Vue({
        el: '#app',
        data: {
            message: 'hello world!',
            isActivated: false,
            activated: '',
            styleObj: {
                fontSize: '22px',
                color: 'black',
                'background-color': 'tan'
            }
        },
        methods: {
            handleDivClick() {
                this.isActivated = !this.isActivated;
                this.activated = this.activated ? '': 'activated';
                this.styleObj.color = this.styleObj.color === 'red' ? 'black':'red';
            }
        }
        
    })
</script>
</html>